package com.sixth.controller;

import com.sixth.entity.*;
import com.sixth.service.PermissionService;
import com.sixth.service.RoleService;
import com.sixth.until.CommonResult;
import com.sixth.until.TableResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: self-tui-education
 * @description:
 * @author: 高振杨
 * @create: 2022-04-15 12:21
 **/
@RestController
@RequestMapping("/system")
public class PermissionController {
    @Autowired
    private PermissionService permissionService;
    @Autowired
    private RoleService roleService;

    @GetMapping("/permission/getAllPermission")
    public CommonResult leftMenu(){
        return permissionService.findMenuByUserid();
    }

    @GetMapping("/permission/findPermissionByRoleId/{roleId}")
    public CommonResult findPermissionByRoleId(@PathVariable String roleId){
        return permissionService.findPermissionByRoleId(roleId);
    }

    @PostMapping("/user/getUserByPage/{currentPage}/{pageSize}")
    public TableResult getUserByPage(@PathVariable Integer currentPage, @PathVariable Integer pageSize, @RequestBody UserVo user){
        //System.out.println(user);
        return  permissionService.getUserByPage(currentPage,pageSize,user);
    }

    @PostMapping("/permission/findAllByPage/{currentPage}/{pageSize}")
    public TableResult findAllByPage(@PathVariable Integer currentPage, @PathVariable Integer pageSize, @RequestBody AclPermission permission){
        //System.out.println(permission);
        return permissionService.findAllpermissionByPage(currentPage,pageSize,permission);
    }
    @PostMapping("/permission/confirmFenPermission")
    public CommonResult confirmFenPermission(@RequestBody PermissionVo permissionVo){
        //System.out.println(permission);
       return permissionService.confirmFenPermission(permissionVo);
    }

    @PostMapping("/role/findRoleByPage/{currentPage}/{pageSize}")
    public TableResult findRoleByPage(@PathVariable Integer currentPage, @PathVariable Integer pageSize, @RequestBody AclRole role){
        //System.out.println(role);
        return  permissionService.findRoleByPage(currentPage,pageSize,role);
    }

    @PostMapping("/user/updateUserByUser")
    public CommonResult updateUserByUser(@RequestBody AclUser user){
        //System.out.println(user);
       return permissionService.updateUserByUser(user);
    }

    @DeleteMapping("/user/deleteUserById/{id}")
    public CommonResult deleteUserById(@PathVariable String id){
        return permissionService.deleteUserById(id);
    }

    @DeleteMapping("/role/deleteRoleById/{roleid}")
    public CommonResult deleteRoleById(@PathVariable String roleid){
        return roleService.deleteRoleById(roleid);
    }

    @PostMapping("/user/updateUserStatusByid/{id}/{deleted}")
    public CommonResult updateUserStatusByid(@PathVariable String id,@PathVariable String deleted){
        return permissionService.updateUserStatusByid(id,deleted);
    }

    @PostMapping("/permission/deleteById")
    public CommonResult deleteById(@RequestBody DeletePermission permissionIds){
        return  permissionService.deleteById(permissionIds);
    }

    @PostMapping("/permission/update")
    public CommonResult update(@RequestBody  AclPermission permission){
        return  permissionService.update(permission);
    }

    @PostMapping("/role/updateRoleStatusByid/{id}/{deleted}")
    public CommonResult updateRoleStatusByid(@PathVariable String id,@PathVariable String deleted){
        return permissionService.updateRoleStatusByid(id,deleted);
    }

    @PostMapping("/user/addUserByUser")
    public CommonResult addUserByUser(@RequestBody AclUser user){
        //System.out.println(user);
        return permissionService.addUserByUser(user);
    }

    @PostMapping("/role/addOrUpdateRole")
    public CommonResult addOrUpdateRole(@RequestBody AclRole role ){

        return roleService.addOrUpdateRole(role);
    }

    @PutMapping("/permission/insert")
    public CommonResult permissioninsert(@RequestBody AclPermission permission){
       return permissionService.permissioninsert(permission);
    }
}
